package com.tencent.bk.core.web.filter;

import com.tencent.bk.core.init.BkConfig;
import com.tencent.bk.core.sdk.paas.PAASClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public abstract class BkAbstractFilter implements Filter {

    protected static final Logger LOG = LoggerFactory.getLogger(BkAbstractFilter.class);

    protected PAASClient paasClient;

    protected BkConfig bkConfig;

    public BkAbstractFilter(PAASClient paasClient, BkConfig bkConfig) {
        this.paasClient = paasClient;
        this.bkConfig = bkConfig;
    }

    @Override
    public void init(FilterConfig config) throws ServletException {
    }

    @Override
    public void destroy() {

    }


    /**
     * 重新登录的跳转
     */
    protected void redirectLogin(HttpServletResponse response, HttpSession session) throws IOException {
        response.sendRedirect(paasClient.getLoginUrl());
        session.invalidate();
    }

}
